﻿using LPY.LeHealth.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServiceStack.OrmLite; 

namespace LPY.LeHealth.DAL
{
    public class ArticleDAL : GenericBaseDAL<ArticleDTO>
	{
		/// <summary>
		/// 添加文章
		/// </summary>
		/// <param name="article"></param>
		/// <returns></returns>
		public bool Add(ArticleDTO article)
		{
			var rtv = DbConnection.Insert<ArticleDTO>(article);
			return rtv > 0;
		}
		/// <summary>
		/// 获取文章列表
		/// </summary>
		/// <returns></returns>
		public List<ArticleDTO> GetList()
		{
			//查询表达式
			var sqlExpression = DbConnection.From<ArticleDTO>().Where(C => true);
			var rtv = DbConnection.Select(sqlExpression).ToList();
			return rtv;
		}
		/// <summary>
		/// 根据id获取文章信息
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public ArticleDTO GetSingle(int id)
		{
			//查询表达式
			var sqlExpression = DbConnection.From<ArticleDTO>().Where(m => m.Id == id);
			//查询
			var rtv = DbConnection.Select(sqlExpression).FirstOrDefault<ArticleDTO>();
			return rtv;
		}

		/// <summary>
		/// 删除文章
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public bool Delete(int id)
		{
			var rtv = DbConnection.DeleteById<ArticleDTO>(id);
			return rtv > 0;
		}
		/// <summary>
		/// 编辑文章信息
		/// </summary>
		/// <param name="article"></param>
		/// <returns></returns>
		public bool Edit(ArticleDTO article)
		{
			var rtv = DbConnection.Update<ArticleDTO>(article);
			return rtv > 0;
		}
	}
}
